package com.attendance.www.hr.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.beans.YearFurloughBean;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.IYearFurloughService;
import com.zhangkongli.frame.core.ResultMap;

/**
 * 年假可用时间设置
 * @author 张鑫
 * 2018-03-19
 *
 */
@Controller
@RequestMapping("/yearFurlough")
public class YearFurloughController {
	
	@Resource
	private IYearFurloughService yearFurloughService;
	
	/**
	 * 增加
	 * @param request
	 * @param yearFurloughBean
	 * @return
	 */
	@RequestMapping(value = "/saveYearFurlough.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object saveYearFurlough(HttpServletRequest request, @RequestBody YearFurloughBean yearFurloughBean) {
		if (yearFurloughBean.getMonth() == null || yearFurloughBean.getYear()== null) {
			throw new ResultFaultException("0_00001");
		}
		return ResultMap.success(yearFurloughService.saveYearFurlough(yearFurloughBean));
	}
	
	/**
	 * 删
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/deleteYearFurlough.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object deleteYearFurlough(HttpServletRequest request) {
		String yearFurloughIdStr = request.getParameter("yearFurloughId");
		if (StringUtils.isBlank(yearFurloughIdStr)) {
			throw new ResultFaultException("0_00001");
		}
		return ResultMap.success(yearFurloughService.deleteYearFurlough(yearFurloughIdStr));
	}
	
	/**
	 * 改
	 * @param request
	 * @param yearFurloughBean
	 * @return
	 */
	@RequestMapping(value = "/updateYearFurlough.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object updateYearFurlough(HttpServletRequest request, @RequestBody YearFurloughBean yearFurloughBean) {
		if (yearFurloughBean.getYearFurloughId() == null || yearFurloughBean.getMonth() == null 
				|| yearFurloughBean.getYear()== null) {
			throw new ResultFaultException("0_00001");
		}
		return ResultMap.success(yearFurloughService.updateYearFurlough(yearFurloughBean));
	}
	
	/**
	 * 查
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getYearFurloughList.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object getYearFurloughList(HttpServletRequest request) {
		return ResultMap.success(yearFurloughService.getYearFurloughList());
	}
	
	/**
	 * 验证该时间是否可用去年年假
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getCheckYearFurlough.do", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Object getCheckYearFurlough(HttpServletRequest request) {
		String yearStr = request.getParameter("yearStr");
		String monthStr = request.getParameter("monthStr");
		if (StringUtils.isBlank(yearStr) || StringUtils.isBlank(monthStr)) {
			throw new ResultFaultException("0_00001");
		}
		return ResultMap.success(yearFurloughService.getCheckYearFurlough(yearStr, monthStr));
	}

}
